package app.repositories.impl;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import app.models.Fornecedor;
import app.repositories.FornecedorRepository;
import app.repositories.Repository;
import app.util.Constants;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class FornecedorRepositoryImpl extends Repository<Fornecedor, Long> implements FornecedorRepository{

	protected FornecedorRepositoryImpl(EntityManager entityManager) {
		super(entityManager);
	}
	
	@SuppressWarnings("unchecked")
	public List<Fornecedor> findLastFornecedores() {
		final Criteria criteria = createCriteria();
		
		criteria.addOrder(Order.desc(Constants.ID));
		criteria.setMaxResults(10);
		
		return criteria.list();
	}

}
